package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.GoToRegister;
import com.cpj.bsyyzx.entity.WorkDiary;
import com.cpj.bsyyzx.service.IWorkDiaryService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/workDiary")
@Log4j
public class WorkDiaryController {
    @Resource
    IWorkDiaryService workDiaryService;
    @RequestMapping("/pagelist")
    CommonResult pagelist(Page page){
        QueryWrapper<WorkDiary> queryWrapper = new QueryWrapper<>();
        log.debug("分页查询");
        IPage<WorkDiary> rpage=workDiaryService.selectPageVo(page,queryWrapper);
        return CommonResult.success(rpage);
    }
    @RequestMapping("/list")
    CommonResult list(Page page, WorkDiary workDiary){
        QueryWrapper<WorkDiary> queryWrapper = new QueryWrapper<>();
        log.debug("分页查询");
        Page<WorkDiary> rpage=workDiaryService.pageList(page,workDiary);
        return CommonResult.success(rpage);
    }
    @RequestMapping("save")
    @ResponseBody
    CommonResult save(WorkDiary workDiary) {

        log.debug("保存");
        boolean success = workDiaryService.saveOrUpdate(workDiary);

        return  CommonResult.success(success) ;
    }
    @RequestMapping("toedit")
    @ResponseBody
    CommonResult toedit(ModelMap modelMap, Integer id) {
        log.debug("跳转到修改页面");
//        User user = userService.getById(id);
//        modelMap.addAttribute("user", user);
        return CommonResult.success(workDiaryService.getById(id));
    }
    @RequestMapping("del/{id}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer id) {
        log.debug("根据主键删除:" + id);
        boolean success = workDiaryService.removeById(id);
        return CommonResult.success(success);
    }

}
